package com.ple.app.jzsf;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ple.app.importdata.Input_Activity;
import com.ple.app.map.MapActivity;
import com.ple.app.push.PushInfoActivity;
import com.ple.app.soil.SoilDataActivity;
import com.ple.app.suggest.Gsetsuggest_Activity;
import com.ple.app.user.UserInfoActivity;

public class MainActivity extends Activity {

    private TextView textViewPush;
    //TextView textViewUserInfo;
    private TextView textViewSoil;
    private TextView textViewImportData;
    private TextView textViewSuggest;
    private TextView textViewMap;
    private TextView textViewUserName;

    private LinearLayout lineLayoutUserInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        initEvents();
    }

    private void initView() {

        lineLayoutUserInfo = (LinearLayout) findViewById(R.id.main_lineLayout_userInfo);
        textViewUserName = (TextView) findViewById(R.id.main_username);
        //textViewUserInfo = (TextView) findViewById(R.id.main_textView_userID);
        textViewPush = (TextView) findViewById(R.id.main_textView_push);
        textViewSoil = (TextView) findViewById(R.id.main_textView_soil);
        textViewImportData = (TextView) findViewById(R.id.main_textView_import);
        textViewSuggest = (TextView) findViewById(R.id.main_textView_suggest);
        textViewMap = (TextView) findViewById(R.id.main_textView_map);

    }

    private void initEvents() {

        lineLayoutUserInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toUserIntent = new Intent(MainActivity.this, UserInfoActivity.class);
                startActivity(toUserIntent);
            }
        });

        textViewSoil.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toSoilIntent = new Intent(MainActivity.this, SoilDataActivity.class);
                startActivity(toSoilIntent);
            }
        });
        textViewImportData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent toImportIntent = new Intent(MainActivity.this, ImportDataActivity.class);
                Intent toImportIntent = new Intent(MainActivity.this, Input_Activity.class);
                startActivity(toImportIntent);
            }
        });
        textViewSuggest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toSuggestIntent = new Intent(MainActivity.this, Gsetsuggest_Activity.class);
                startActivity(toSuggestIntent);
            }
        });
        textViewMap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toMapIntent = new Intent(MainActivity.this, MapActivity.class);
                startActivity(toMapIntent);
            }
        });
        textViewPush.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toPushIntent = new Intent(MainActivity.this, PushInfoActivity.class);
                startActivity(toPushIntent);
            }
        });
    }

    public  void  setUsername(){
        if(getIntent().getStringExtra("username") != null) {
            textViewUserName.setText(getIntent().getStringExtra("username"));
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        setUsername();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUsername();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }
}
